package com.pdg.mcplugin.common.baseclasses;

import java.util.HashMap;
import java.util.Map;

import com.pdg.mcplugin.common.interfaces.MessageManager;
import com.pdg.mcplugin.common.interfaces.Messages;

public class MessageManagerBase<E extends PluginBase,M extends Messages> extends PluginClientBase<E> implements MessageManager<M>{

	public MessageManagerBase(E thePlugin) {
		super(thePlugin);
	}

	private Map<M,String> messageTextCache = new HashMap<M,String>();
	private Map<M,Boolean> messageEnabledCache = new HashMap<M,Boolean>();
	
	public Boolean isMessageEnabled(M theMessage){
		if(!messageEnabledCache.containsKey(theMessage)){
			messageEnabledCache.put(theMessage, getPlugin().getConfig().getBoolean(theMessage.getEnabledNode()));
		}
		return messageEnabledCache.get(theMessage);
	}
	
	public String getMessageText(M theMessage){
		if(!messageTextCache.containsKey(theMessage)){
			messageTextCache.put(theMessage, getPlugin().getConfig().getString(theMessage.getTextNode()));
		}
		return messageTextCache.get(theMessage);
	}
}
